﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DocumentList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitMenu();
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        if (!IsPostBack)
        {
            
            var categorys = from category in dc.Document_Categories
                            orderby category.Category_id
                            select new
                            {
                                类别编号 = category.Category_id,
                                类别名称 = category.Category_name
                            };
            Document_Categroy.DataSource = categorys;
            Document_Categroy.DataBind();
        }

        var documents = from document in dc.Documents
                        join document_category in dc.Document_Categories
                        on document.Document_category equals document_category.Category_id
                        where document_category.Category_id.Equals(Convert.ToInt32(Document_Categroy.SelectedValue))
                        orderby document.Time descending
                        select new
                        {
                            标识 = document.Document_id,
                            标题 = document.Title,
                            日期 = document.Time.Value.Month + "-" + document.Time.Value.Day
                        };

        NewsListGridView.DataSource = documents;
        NewsListGridView.DataBind();

        dc.Dispose();
    
    }
    protected void NewsListGridView_OnSelectedIndexChange(object sender, GridViewSelectEventArgs e)
    {
        Session.Add("Document_id", ((Label)NewsListGridView.Rows[e.NewSelectedIndex].FindControl("News_id")).Text);
       // Response.Redirect("Document.aspx");
        Page.RegisterStartupScript("", "<script>window.open('Document2.aspx')</script>");
    }

    protected void DocumentCategroy_SelectedIndexChanged(object sender, EventArgs e)
    {
        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        var documents = from document in dc.Documents
                        join document_category in dc.Document_Categories
                        on document.Document_category equals document_category.Category_id
                        where document_category.Category_id.Equals(Convert.ToInt32(Document_Categroy.SelectedValue))
                        select new
                        {
                            标识 = document.Document_id,
                            标题 = document.Title,
                            日期 = document.Time.Value.Month + "-" + document.Time.Value.Day
                        };
        NewsListGridView.DataSource = documents;
        NewsListGridView.DataBind();

    }
    protected void InitMenu()
    {

        OfficeDataClassesDataContext dc = new OfficeDataClassesDataContext();
        MainMenu.Items.Clear();
        MenuItem MainPage = new MenuItem();
        MainPage.Enabled = true;
        MainPage.Selectable = true;
        MainPage.Selected = false;
        MainPage.Value = MainPage.ToolTip = MainPage.Text = "首页";
        MainPage.NavigateUrl = "Default.aspx";
        MainMenu.Items.Add(MainPage);
        var Menus = from menu in dc.Menus
                    select new
                    {
                        MenuItem_id = menu.MenuItem_id,
                        MenuItem_Name = menu.MenuItem_Name
                    };
        foreach (var menu in Menus)
        {
            MenuItem menuitem = new MenuItem();
            menuitem.Enabled = true;
            menuitem.Selectable = true;
            menuitem.Selected = false;
            menuitem.ToolTip = menuitem.Text = menu.MenuItem_Name.Trim();
            menuitem.Value = menu.MenuItem_id.ToString();
            if (menu.MenuItem_id == 2)
            {
                menuitem.NavigateUrl = "http://binhai.nankai.edu.cn/script/binhai/CollegeLeaderPage.htm";
            }
            else if (menu.MenuItem_id == 3)
            {
                menuitem.NavigateUrl = "OrgnizationList.aspx";
            }
            else if (menu.MenuItem_id == 4)
            {
                menuitem.NavigateUrl = "RuleList.aspx";
            }
            else if (menu.MenuItem_id == 5)
            {
                menuitem.NavigateUrl = "MeetingList.aspx";
            }
            else if (menu.MenuItem_id == 6)
            {
                menuitem.NavigateUrl = "CollegeConditionList.aspx";
            }
            else if (menu.MenuItem_id == 7)
            {
                menuitem.NavigateUrl = "LawList.aspx";
            }
            else if (menu.MenuItem_id == 8)
            {
                menuitem.NavigateUrl = "ResourceOnline.aspx";
            }
            MainMenu.Items.Add(menuitem);
        }
        dc.Dispose();
    }

    protected void NewsListGridView_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void NewsListGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        NewsListGridView.PageIndex = e.NewPageIndex;
        DataBind(); //重新绑定GridView数据的函数
    }

}
